import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Level, LevelRelation, OrganizationLevelRelation } from '../domain/level';
import { Organization } from '../domain/organization';

@Injectable({
  providedIn: 'root'
})
export class LevelService {
  getParentOrganizations(positionLevelId: any) {
    return this.httpClient.get<Organization[]>(this.host+"/positionLevels/getParentOrganizations",{ params:{positionLevelId:positionLevelId}})
  }
  host:string = "http://localhost:8091/api";

  constructor(private httpClient: HttpClient) { }

  public getParents(organizationId: string, positionLevelId: string) {
    return this.httpClient.get<any>(this.host+"/positionLevels/getParents",{ params:{organizationId:organizationId,positionLevelId:positionLevelId}})
  }

  public getTreeByParentId(parentId: string){
    return this.httpClient.get<any>(this.host+"/positionLevels/getTreeByParentId",{ params:{parentId:parentId}})
  }

  public saveBatch(levels: Level[]){
    return this.httpClient.post(this.host+"/positionLevels/batch",levels);
  }

  public save(level: Level){
    return this.httpClient.post<Level>(this.host+"/positionLevels",level);
  }

  public saveRelations(levelRelations: OrganizationLevelRelation[]){
    return this.httpClient.post(this.host+"/positionLevels/relations/batch",levelRelations);
  }

  public getModelName(){
    return this.httpClient.get<any>(this.host+"/positionLevels/getModelName");
  }

  deleteBatch(ids$: any) {
    return this.httpClient.delete(this.host+"/positionLevels/batch",{body:ids$});
  }
}
